<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>融资筛选列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 tabel_col clearFix">
        <c:if test="${flag == '1'}">
         <div class="fieldBox col_100" >
                <div class="label">导入资产包</div>
                <div class="field">
                 <span id="searAssBtn"  class="sq-button sq-button-round" onclick="searAss();">选择资产包</span>
                </div>
            </div>
        </c:if>
        <div class="fieldBox col_33">
                <div class="label">资产包名称</div>
                <div class="field">
                   <input name="assPackNm" id="assPackNm" type="text" class="ui-textbox" value="" ligerui="width: 200">
                </div>
            </div>
          <div class="fieldBox col_33" >
                <div class="label">融资基数</div>
                <div class="field">
                <input name="fncCrdnlt" id="fncCrdnlt" type="text" class="ui-textbox" data-name="fncCrdnlt" value="" >
                <%-- <select name="fncCrdnlt" id="fncCrdnlt" data-value=" " data-name="fncCrdnlt">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${fncCrdnltList }" var="fc">
                     		<option value="${fc.key }">${fc.value }</option>
                        </c:forEach>
                </select> --%>
                </div>
            </div> 
            <div class="fieldBox col_33">
                <div class="label">计划融资日期</div>
                <div class="field">
                <input name="stdt" id="stdt" type="text" class="ui-textbox" data-name="stdt" value="" >
                <span>—</span>
				<input name="eddt" id="eddt" type="text" class="ui-textbox" data-name="eddt" value="" >
                   <!-- <input name="stdt" id="stdt" type="text" class="ui-datepicker" value="" >
                   <span>—</span>
                   <input name="eddt" id="eddt" type="text" class="ui-datepicker" value="" > -->
                </div>
            </div>
			<div class="fieldBox col_33">
                <div class="label">客户类型</div>
                <div class="field">
                <input name="cstTypCd" id="cstTypCd" type="text" class="ui-textbox" data-name="cstTypCd" value="" >
                    <%-- <select name="cstTypCd" id="cstTypCd" data-value=" " data-name="fncCrdnlt">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${cstTypCdList }" var="ct">
                     		<option value="${ct.key }">${ct.value }</option>
                        </c:forEach>
                    </select> --%>
                </div>
            </div>        
			<div class="fieldBox col_33">
                <div class="label">所属事业部</div>
                <div class="field">
                <input name="buOrgCd" id="buOrgCd" type="text" class="ui-textbox" data-name="buOrgCd" value="" ligerui="width: 200">
                    <%-- <select name="buOrgCd" id="buOrgCd" data-value=" " data-name="fncCrdnlt">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${buOrgCdList }" var="bo">
                     		<option value="${bo.key }">${bo.value }</option>
                        </c:forEach>
                    </select> --%>
                </div>
            </div>        
			<div class="fieldBox col_33">
                <div class="label">是否办理抵押</div>
                <div class="field">
                <input name="isMortgage" id="isMortgage" type="text" class="ui-textbox" data-name="isMortgage" value="" >
                    <%-- <select name="isMortgage" id="isMortgage" data-value=" " data-name="isMortgage">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${isMortgageList }" var="im">
                     		<option value="${im.key }">${im.value }</option>
                        </c:forEach>
                    </select> --%>
                </div>
            </div>        
			<div class="fieldBox col_33">
                <div class="label">是否有保险</div>
                <div class="field">
                <input name="isInsurance" id="isInsurance" type="text" class="ui-textbox" data-name="isInsurance" value="" >
                    <%-- <select name="isInsurance" id="isInsurance" data-value=" " data-name="isInsurance">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${isMortgageList }" var="im">
                     		<option value="${im.key }">${im.value }</option>
                        </c:forEach>
                    </select> --%>
                </div>
            </div>        
            <div class="fieldBox col_33">
                <div class="label">租赁期数</div>
                <div class="field">
                   <input name="leaseTermMinQ" id="leaseTermMinQ" type="text" class="ui-textbox" data-name="leaseTermMinQ" value="">
                   <span>—</span>
                   <input name="leaseTermMaxQ" id="leaseTermMaxQ" type="text" class="ui-textbox" data-name="leaseTermMaxQ" value="">
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">剩余租赁期数</div>
                <div class="field">
                   <input name="surplusLeaseTermMinQ" id="surplusLeaseTermMinQ" type="text" data-name="surplusLeaseTermMinQ" class="ui-textbox" value="">
                   <span>—</span>
                   <input name="surplusLeaseTermMaxQ" id="surplusLeaseTermMaxQ" type="text" data-name="surplusLeaseTermMaxQ" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">起租日期</div>
                <div class="field">
                   <input name="stDtQ" id="stDtQ" type="text" class="ui-textbox" data-name="stDtQ" value="" >
                   <span>—</span>
                   <input name="edDtQ" id="edDtQ" type="text" class="ui-textbox" data-name="edDtQ" value="" >
                </div>
            </div>
           <div class="fieldBox col_33">
                <div class="label">逾期天数</div>
                <div class="field">
                   <input name="ovdDaysMin" id="ovdDaysMin" type="text" class="ui-textbox" data-name="ovdDaysMin" value="">
                   <span>—</span>
                   <input name="ovdDaysMax" id="ovdDaysMax" type="text" class="ui-textbox" data-name="ovdDaysMax" value="">
                </div>
            </div>
             <div class="fieldBox col_33">
                <div class="label">可用授信金额</div>
                <div class="field">
                   <input name="crBal" id="crBal" type="text" class="ui-textbox" value="${cbvo.crBal}">
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox formBtns notRight">
            	<!-- 隐藏融资筛选编号 -->
				<input name="applyId" id="applyId" type="hidden"  value="${id}">
				<input name="prjid" id="prjid" type="hidden"  value="${prjid}">
				<input name="paySchCount" id="paySchCount" type="hidden"  value="">
				<input name="acFiAmt" id="acFiAmt" type="hidden"  value="">
				<input name="flag" id="flag" type="hidden"  value="${flag}">
				
				<span id="expBtn" class="sq-button-round" onclick="exportexcel();">导出excel</span>
            	<c:if test="${flag == '1'}">
	                <span id="addBtn" class="sq-button-round" onclick="add();">新增</span>
	                <span id="clearBtn" class="sq-button-round" onclick="deleteRow();">删除</span>
            		<span id="clearAll" class="sq-button-round" onclick="clearAll();">删除所有</span>
            	</c:if>
            	<c:if test="${flag == '-1'}">
            		<span id="searchBtn" class="sq-button-round">查询</span>
            	</c:if>
            </div>
          </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>

<form id="fnc_prj_bsc_info_form"  method="post">
<input name="jsonArrayData" id="jsonArrayData" type="hidden"  value="">
<input name="prjid1" id="prjid1" type="hidden"  value="${prjid}">
<input name="id1" id="id1" type="hidden"  value="">
</form>
<script type="text/javascript">
	$(function () {
		initData();
	});
	
	var grid = null;
	var applyId = $("#applyId").val();
	var fncCrdnlt = '';
	var stdt = '';
	var eddt = '';
	var griddata1;
	//初始化数据
	function initData(){
    	if(!applyId)return;
    	var _url = '<%=path%>/ass/asspackinfo/getById.do';
    	AjaxUtils.ajaxGet(_url, {id:applyId}, initCallback);
	}
	
	//初始化回调
	function initCallback(msg){
		if(msg.success == 1){
      
			 setData(msg.data);//设置数据
		 }else{
			 UIUtils.alertError(msg.info);
		 }
	}
	
	//修改时候设置页面数据
    function setData(data){
		$("#fncCrdnlt").val(data.fncCrdnltNm);
		$("#stdt").val(data.planStdt);
		$("#eddt").val(data.planEddt);
		$("#cstTypCd").val(data.cstTypCdNm);
		$("#buOrgCd").val(data.buOrgCdNm);
		$("#isMortgage").val(data.isMgtNm);
		$("#isInsurance").val(data.isInsureNm);
		$("#leaseTermMinQ").val(data.leaTermB);
		$("#leaseTermMaxQ").val(data.leaTermE);
		$("#surplusLeaseTermMinQ").val(data.reLeaTermB);
		$("#surplusLeaseTermMaxQ").val(data.reLeaTermE);
		$("#stDtQ").val(data.flDateBegin);
		$("#edDtQ").val(data.flDateEnd);
		$("#ovdDaysMin").val(data.odDateB);
		$("#ovdDaysMax").val(data.odDateE);
		$("#assPackNm").val(data.assPackNm);
   		$('form').find('input').prop("disabled", true);
   		
    	fncCrdnlt = data.fncCrdnlt;
    	stdt = data.planStdt;
    	eddt = data.planEddt;
    	initGrid();
	};
	
	//初始化列表
	function initGrid() {
		var _url = '<%=path%>/rfbuss/fncprjbscinfo/fncPrjPayRltvInfo.do';
		griddata1=$("#ligergrid1").ligerGrid({
    		url : _url,
    		method : 'get',
    		parms : {"id":applyId,"fncCrdnlt":fncCrdnlt,"stdt":stdt,"eddt":eddt},
        	columns: [
        		{ display: '再融资状态', name: 'financingTypeNm', width: 80},
        		{ display: '是否预约', name: 'isYl', width: 60,
	            	render: function (rowdata, rowindex, value){
	            		if(rowdata.isYl == '1' ){
	            			var h="是";
	            		}else{
	            			var h="否";
	            		}
	            		return h;
	            	}
	            },
	            { display: '客户名称', name: 'cstNm', width: 150 },
	            { display: '客户类型', name: 'cstTypNm', width: 100 },
	            { display: '合同编号', name: 'contractNumber', width: 150 },
	            { display: '事业部', name: 'buOrgNm', width: 150 },
	            { display: '支付表编号', name: 'paySchId', width: 200, 
	            	 totalSummary:
	                    {
	                        render: function (suminf, column, cell)
	                        {
	                        	//alert(suminf.count+":"+suminf.sum);
	                       //// 	$("#paySchCount").val(suminf.count);
	                            return '<div>总共:' + suminf.count + '</div>';
	                        },
	                        align: 'left'
	                    }
	            },
	            { display: '起租日期', name: 'stDate', width: 150, render:renderDate},
	            { display: '可融资金额', name: 'financingAmount', width: 150,
	            	 totalSummary:
	                    {
	                        render: function (suminf, column, cell)
	                        {
	                        ////	$("#acFiAmt").val(suminf.sum);
	                        	
	                        //alert(	$("#acFiAmt").val());
	                          
	                            //alert($("#paySchCount").val()+":"+$("#acFiAmt").val());
	                            if("${flag}"=="1"){
	                            	save($("#paySchCount").val(),$("#acFiAmt").val());	
	                            	
	                            }
	                    
	                        	var str='<div>总和:' + suminf.sum + '</div>';
	                        	var flag="${flag}";
	                        	if(parseInt($("#crBal").val())<suminf.sum && flag=="1"){
	                        	////	 str='<div > <span style="color:red">授信余额不足！总和:' + suminf.sum + '</span></div>';
	                        	}
	                        	  return str;
	                        },
	                        align: 'left'
	                    }
	
	            
	            }
	        ],
	        pageSize:10, 
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        rownumbers:true,
	        isChecked: f_isChecked, 
	        onCheckRow: f_onCheckRow, 
	        onCheckAllRow: f_onCheckAllRow
    	});
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	}

	
	$("#searchBtn").click(function(event) {
	    var form = new liger.get("searchBar");
	    var data = form.getData();
	    for (var name in data){
	       grid.setParm(name,data[name]);
	    };
	   grid.reload();
	});
	
	function f_onCheckAllRow(checked){
        for (var rowid in this.records){
            if(checked)
                addCheckedCustomer(this.records[rowid]['id']);
            else
                removeCheckedCustomer(this.records[rowid]['id']);
        }
    }

    /*
    该例子实现 表单分页多选
    即利用onCheckRow将选中的行记忆下来，并利用isChecked将记忆下来的行初始化选中
    */
    var checkedCustomer = [];
    function findCheckedCustomer(CustomerID){
        for(var i =0;i<checkedCustomer.length;i++){
            if(checkedCustomer[i] == CustomerID) return i;
        }
        return -1;
    }
    function addCheckedCustomer(CustomerID){
        if(findCheckedCustomer(CustomerID) == -1)
            checkedCustomer.push(CustomerID);
    }
    function removeCheckedCustomer(CustomerID){
        var i = findCheckedCustomer(CustomerID);
        if(i==-1) return;
        checkedCustomer.splice(i,1);
    }
    function f_isChecked(rowdata){
        if (findCheckedCustomer(rowdata.id) == -1)
            return false;
        return true;
    }
    function f_onCheckRow(checked, data){
        if (checked) addCheckedCustomer(data.id);
        else removeCheckedCustomer(data.id);
    }
    function f_getChecked(){
        alert(checkedCustomer.join(','));
    }
	
	 //新增数据
	function add(){
		$.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 1000,
            height:600,
            title : '资产筛选列表',
            url:'<%=path%>/ass/asspackinfo/toListPage.do?prjid=${prjid}&id='+applyId,
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });	 
	}
	 
	 //删除所选
	function deleteRow(){
		if(checkedCustomer.join(',') != ''){
			$.ligerDialog.confirm('确定删除吗?', function (flag) {
				if(flag == false)return;
				var _payRltvInfo = checkedCustomer.join(',');
				var _url = '<%=path%>/ass/asspackinfo/deletePayRltvInfo.do';
				//发送异步请求校验
				var wait_dialog;
				$.ajax({
					type: 'post',
					dataType: 'json',
					data: {"payRltvInfo":_payRltvInfo,"assPackId":applyId},
					url: _url,
					beforeSend: function(){
				          wait_dialog=top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					},
					success:function(msg){
						 wait_dialog.close();
						 if(msg.success == 1){
							top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
							grid.reload();
						 }else if(msg.success == 0 && !msg.data){//校验不成功,且没有data(id)报错
							top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
						 }
					}
				});
			});
		}else{
			top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
	    	return false; //验证不通过，不执行以下代码
		}
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	
	//格式化在融资状态
	function renderRltvId(rowdata, index, value){
		var dateStr = "正常";
		if(null != value && value != 0){
			dateStr = "已占用";
		}
		return dateStr;
	}
	
	//刷新列表
	function reloadAssPackInfoList(){
		initData();
	}
    
	function searAss(){
		var prjid="${prjid}";
		$.ligerDialog.SQopen(
				{
					title: '导入资产包', 
					height: 800,
					width: 1200, 
					url: '<%=path%>/rfbuss/fncprjbscinfo/toAssPackInfoPage.do?prjid='+prjid, 
				
				isResize: true 
				});		
	
	}
	
	function save(paySchCount,fncfiamt){
       // var ligerForm = liger.get("fnc_prj_bsc_info_form");
       //alert(paySchCount);
	    	var data = {};
	    	data["id"]=$("#prjid").val();
	    	data["fncfiamt"]=fncfiamt;
	    	data["paySchCount"]=paySchCount;
	    	var url = '<%=path%>/rfbuss/fncprjbscinfo/add.do';

	    	var wait_dialog;
	    			        $.ajax({
	    			    		type: 'post',
	    			    		dataType:'json',
	    			    		data:data,
	    			    		url: url,
	    			    		beforeSend: function(){
	    					          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	    					     },
	    			    		success:function(msg){
	    			    			 wait_dialog.close();
	    			    			 if(msg.success == 1){
	    			    					// top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
	    						          	 	$("#prjid").val(msg.data);
	    						          	 	pageInApp.flag=false;
	    			    			 }else{
	    			    				// top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    			    			 }
	    			    		}
	    			    	});
     	    	
	}
	
	function exportexcel(paySchCount,fncfiamt){
	       // var ligerForm = liger.get("fnc_prj_bsc_info_form");
		    //	var data = {};
		    //	data["id"]=$("#prjid").val();
		    
		    //	data["jsonArrayData"]=JSON.stringify(griddata1.getData());
		   var parms="id="+applyId+"&fncCrdnlt="+fncCrdnlt+"&stdt="+stdt+"&eddt="+eddt+"&page=1&pagesize=10000";
		    	$("#jsonArrayData").val(JSON.stringify(griddata1.getData()))
		    	var url = '<%=path%>/rfbuss/fncprjbscinfo/exportExcel.do?'+parms;
		    	//alert($("#jsonArrayData").val());
		    	//alert($("#prjid1").val());
		    	var wait_dialog;
		        $('#fnc_prj_bsc_info_form').attr('action', url);  
		         $('#fnc_prj_bsc_info_form').submit();  
		    	/*
		    	 $.ajax({
		    			    		type: 'post',
		    			    		dataType:'json',
		    			    		data:data,
		    			    		url: url,
		    			    		beforeSend: function(){
		    					          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		    					     },
		    			    		success:function(msg){
		    			    			 wait_dialog.close();
		    			    			 if(msg.success == 1){
		    			    					// top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
		    						          	 //	$("#prjid").val(msg.data);
		    						          	 //	pageInApp.flag=false;
		    			    			 }else{
		    			    				// top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
		    			    			 }
		    			    		}
		    			    	});
		    	
		    	
		    	*/
		    			       
	     	    	
		}
	 //删除所有
	function clearAll(){
			$.ligerDialog.confirm('确定删除所有吗?', function (flag) {
				if(flag == false)return;
				var _url = '<%=path%>/ass/asspackinfo/deletePayRltvInfoAll.do';
				//发送异步请求校验
				var wait_dialog;
				$.ajax({
					type: 'post',
					dataType: 'json',
					data: {"assPackId":applyId},
					url: _url,
					beforeSend: function(){
				          wait_dialog=top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					},
					success:function(msg){
						 wait_dialog.close();
						 if(msg.success == 1){
							top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
							grid.reload();
						 }else if(msg.success == 0 && !msg.data){//校验不成功,且没有data(id)报错
							top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
						 }
					}
				});
			});
		
	}
</script>
</body>
</html>